<?php
class StatisticsController extends ControllerBase{
	
	public function __contruct(){
		parent::__construct();
		// Set city name
		$this->setPageName ( 'admin_Statistics' );
		
		// Init Authentication class
		$authentication = new Authentication ();
		
		// Only administrator can right
		if ($authentication->isAdministrator () == false) {
			
			// Go to login city
			$url = Zend_Registry::get ( 'config' )->APPLICATION_URL . '/Admin/Login/index';
			CommonUtils::redirect ( $url );
		}
		
		// Get status list of city category
		//$this->smarty->assign ( 'statusList', CityEntity::getStatusList() );
		
		// New city Data Service
		$this->DealOrderDataService = new DealOrderDataService ();
	}
//	public function listAction() {
//		
//		$this->smarty->assign ( 'SMARTY_CONTENT_PATH', 'Admin/Statistics/statistics.tpl' );
//		$this->smarty->display ( APPLICATION_PATH . '/Layouts/Admin/MainLayout.tpl' );
//		$this->listAction ();
//	}
	public function indexAction(){
		$this->smarty->assign ( 'SMARTY_CONTENT_PATH', 'Admin/Statistics/index.tpl' );
		$this->smarty->display ( APPLICATION_PATH . '/Layouts/Admin/MainLayout.tpl' );
	}
	public function DealOrderStatisticAction(){
		$isError = false;
		$msg = "";
		$isPost = 'false';
		// Get action method and check it
		$actionForm = $this->getPost ( 'submit', '' );
		if(!empty($actionForm)){
			$dateTo = $this-> getPost('dateTo','');
			$dateEnd = $this-> getPost('dateEnd','');
			if (!empty($dateTo)
			&& !empty($dateEnd)){
				try {
					$dealorderDataService = new DealOrderDataService();
					$items = $dealorderDataService->DealOrderStatistics($dateTo,$dateEnd);
					$isPost = 'true';
					$this->smarty->assign('dateTo',$dateTo);
					$this->smarty->assign('dateEnd',$dateEnd);
					$this->smarty->assign('items',$items);
					$this->smarty->assign('isPost',$isPost);
					//var_dump($items);
				} catch (Exception $e) {
				}
				
			}
		}
		$this->createActionKey ();
		$this->smarty->assign ( 'SMARTY_CONTENT_PATH', 'Admin/Statistics/statisticsDeal.tpl' );
		$this->smarty->display ( APPLICATION_PATH . '/Layouts/Admin/MainLayout.tpl' );
	}
	public function CategoryOrderStatisticAction(){
		$isError = false;
		$msg = "";
		$isPost = 'false';
		// Get action method and check it
		$actionForm = $this->getPost ( 'submit', '' );
		if(!empty($actionForm)){
			$dateTo = $this-> getPost('dateTo','');
			$dateEnd = $this-> getPost('dateEnd','');
			if (!empty($dateTo)
			&& !empty($dateEnd)){
				try {
					$dealorderDataService = new DealOrderDataService();
					$items = $dealorderDataService->CategoryOrderStatistics($dateTo, $dateEnd);
					$isPost = 'true';
					$this->smarty->assign('dateTo',$dateTo);
					$this->smarty->assign('dateEnd',$dateEnd);
					$this->smarty->assign('items',$items);
					$this->smarty->assign('isPost',$isPost);
					
				} catch (Exception $e) {
				}
			}
		}
		$this->createActionKey ();
		$this->smarty->assign ( 'SMARTY_CONTENT_PATH', 'Admin/Statistics/statisticsCate.tpl' );
		$this->smarty->display ( APPLICATION_PATH . '/Layouts/Admin/MainLayout.tpl' );
	}
	public function SalesStatisticAction(){
		$isError = false;
		$msg = "";
		$isPost = 'false';
		// Get action method and check it
		$actionForm = $this->getPost ( 'submit', '' );
		if(!empty($actionForm)){
			$dateTo = $this-> getPost('dateTo','');
			$dateEnd = $this-> getPost('dateEnd','');
			if (!empty($dateTo)
			&& !empty($dateEnd)){
				try {
					$dealorderDataService = new DealOrderDataService();
					$items = $dealorderDataService->SalesStatistics($dateTo, $dateEnd);
					$this->smarty->assign('dateTo',$dateTo);
					$this->smarty->assign('dateEnd',$dateEnd);
					$this->smarty->assign('items',$items);
					$this->smarty->assign('isPost',$isPost);
					//var_dump($items);
				} catch (Exception $e) {
				}
			}
		}
		$this->createActionKey ();
		$this->smarty->assign ( 'SMARTY_CONTENT_PATH', 'Admin/Statistics/statisticsSales.tpl' );
		$this->smarty->display ( APPLICATION_PATH . '/Layouts/Admin/MainLayout.tpl' );
	}
}